package it.creazionicreative.engine;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import android.location.Location;
import android.util.Log;

public class EngineManager {
	public List<BaseEngine> engines = new LinkedList<BaseEngine>();

	public EngineManager() {

	}


	private boolean checkEngineExists(String name)
	{
		boolean ret = false;

		for (Iterator<BaseEngine> it = engines.iterator(); it.hasNext();)
		{
			BaseEngine be = it.next();
			if (be.getEngineName().equals(name))
				ret = true;
		}		
		return ret;
	}

	public void addEngine(BaseEngine be)
	{
		if (!checkEngineExists(be.getEngineName()))
		{
			engines.add(be);
			be.Init();			
		}
		else
		{
			Log.i("EngineManager", String.format("Engine %s already exists", be.getEngineName()));
		}
	}

	public BaseEngine getEngine(String name)
	{
		BaseEngine eng = null;
		for (Iterator<BaseEngine> it = engines.iterator(); it.hasNext();)
		{
			
			BaseEngine be = it.next();
			if (be.getEngineName().equals(name))
				eng = be;
		}	

		return eng;
	}

	public void Shutdown()
	{
		for (Iterator<BaseEngine> it = engines.iterator(); it.hasNext();)
		{
			BaseEngine be = it.next();
			be.Shutdown();			
		}		
	}

}
